
//
//  MCChooseForPlatformCell.swift
//  StoreManage
//
//  Created by MC on 2018/2/5.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

protocol MCSpecificationsCellDelegate : NSObjectProtocol {
    func MCSpecificationsCellDelete(row:Int)
    func MCSpecificationsCellEdit(row:Int)

}

class MCSpecificationsCell: UITableViewCell {
    
    
    var model : MCSpecificationsModel = MCSpecificationsModel() {
        didSet {
            iconImageView.sd_setImage(with: URL.init(string: model.imagePath), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
            specLabel.text = model.specification
            moneyLabel.text = MCString_judgemantDecimalsIsZero(figure: model.salePrice)
            numberLabel.text = "库存:" + String(model.inventoryNum)
        }
    }
    
    weak var delegate : MCSpecificationsCellDelegate?
    var row = 0
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(1)
        }
        
        self.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(self)
            make.left.equalTo(10)
            make.size.equalTo(CGSize.init(width: 80, height: 80))
        }
        
        self.addSubview(numberLabel)
        numberLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(iconImageView.snp.right).offset(5)
            make.bottom.equalTo(iconImageView).offset(0)
        }

        
        self.addSubview(moneyLabel)
        moneyLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(numberLabel)
            make.bottom.equalTo(numberLabel.snp.top).offset(-5)
        }
        
        
        self.addSubview(suggestLabel)
        suggestLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(numberLabel.snp.right).offset(5)
            make.centerY.equalTo(moneyLabel)
        }

        
        self.addSubview(specLabel)
        specLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(numberLabel)
            make.top.equalTo(iconImageView)
            make.right.equalTo(-10)
            make.bottom.lessThanOrEqualTo(moneyLabel.snp.top).offset(-5)
        }

        self.addSubview(editButton)
        editButton.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(numberLabel)
            make.right.equalTo(-10)
            make.size.equalTo(CGSize.init(width: 70, height: 40))
        }

        
        self.addSubview(deleteButton)
        deleteButton.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(editButton)
            make.right.equalTo(editButton.snp.left).offset(5)
            make.size.equalTo(CGSize.init(width: 70, height: 40))
        }

        

        

        
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func editButtonClicked() {
        delegate?.MCSpecificationsCellEdit(row: row)
    }
    
    @objc func deleteButtonClicked() {
        delegate?.MCSpecificationsCellDelete(row: row)
    }
    
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_placeholder_1_1")
        imageView.layer.borderColor = UIColor.MCGray_light.cgColor
        imageView.layer.borderWidth = 1
        return imageView
    }()
    
    
    lazy var specLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.black
        label.numberOfLines = 0
        label.font = MCFont(14)
        return label
    }()
    
    lazy var moneyLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.MCMain
        label.text = "¥0"
        label.font = MCFont(13)
        return label
    }()
    
    lazy var suggestLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.MCGray_middle
        label.text = "市场价:¥0"
        label.font = MCFont(12)
        return label
    }()

    
    lazy var numberLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.MCGray_middle
        label.text = "库存:0"
        label.font = MCFont(12)
        return label
    }()

    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
    
    lazy var editButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "GoodsManage_edit").MCImageWithTintColor(color: UIColor.MCGray_middle), for: UIControlState.normal)
        button.setTitle(" 删除", for: .normal)
        button.titleLabel?.font = MCFont(12)
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.right
        button.setTitleColor(UIColor.MCBlack, for: .normal)
        button.addTarget(self, action: #selector(editButtonClicked), for: UIControlEvents.touchUpInside)
        return button
    }()
    
    lazy var deleteButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "Reuse_delete").MCImageWithTintColor(color: UIColor.MCGray_middle), for: UIControlState.normal)
        button.setTitle(" 删除", for: .normal)
        button.titleLabel?.font = MCFont(12)
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.right
        button.setTitleColor(UIColor.MCBlack, for: .normal)
        button.addTarget(self, action: #selector(deleteButtonClicked), for: UIControlEvents.touchUpInside)

        return button
    }()

}

